<?php
/**
 * класс для вывода всего что связано со статьями (пользователь сообщества общие)
 *
 * @author Горбачев Максим
 * @version 1.0
 */
class View_Article{
  /**
   * выводим список статей
   */
  public static function displayArticles(array $arrArticle, $fullSizeFlag = false, $folderFlag = false){
    if ($arrArticle){
    	foreach ($arrArticle as $arrArticle)
      	self::displayArticleInColumn($arrArticle, $fullSizeFlag, $folderFlag);
    }
    else
    	self::_showNoContent();
  }

  /**
   * выводит статью полностью
   *
   * @param array $arrArticle
   */
  public static function displayArticle(array $arrArticle, &$arrStarsControls = NULL){
  	echo '
		<div class="main_article">
			<div class="item_text_info">
				<div class="text_info_left">
					<div class="text_info_right">
						<div class="item">
							<h1 class="crumb ">
								' . ($arrArticle['draft'] ? '<a href="' . W_ABSPATH . 'draft">Черновик</a>' : '') . '
								<a href="' . W_ABSPATH . 'articles">Статьи</a>
								' . self::getArticleEssence($arrArticle) . '
								<span>' . $arrArticle['name'] . '</span>
							</h1>
							<div class="top_info_text">
								<ul class="rating">
									<li class="one">' . round($arrArticle['total_mark'], 2) . '</li>' .
									($arrArticle['essence_type'] != 14 ? '<li class="second">' . $arrArticle['average_complexity_mark'] . '</li>' : '') . '
									<li class="coments"><a href="#comments">' .  $arrArticle['comment_amount'] . '</a></li>
								</ul>
								<div class="right_ifno_text">
									<ul class="info_coments">
										<li class="date">' . Service_Date::getCaseDateForUser($arrArticle['creation']) . '</li>
										<li class="user"><a href="' . W_ABSPATH . 'user/' .  $arrArticle['login'] . '/">' . $arrArticle['login'] . '</a></li>
									</ul>
										' . View_Tags::showTagsInList($arrArticle['tags'], 1, 'all_tags') . '
								</div>
								<div class="floatRight"><a class="none readerHref" href="javascript:reader.activateReadar();"><img alt="Режим чтения" title="Режим чтения" src="' . W_IMAGES . 'icons/kghostview.png"/></a></div>
							</div>
							<div class="article_text wysiwyg-content">
							' . $arrArticle['annotation'] . '
								<a name="cut"></a><br />
							' . $arrArticle['text'] . '
							</div>';
							global $arrUserInfo;
							//if ($arrUserInfo['role'] == 2) {
								echo '<div id="social">';
									echo '<div class="service">';
										echo '<script src="' . W_JS . 'bookmarks.js" type="text/javascript"></script>';
									echo '</div>';
									echo '<div class="service" id="vkshare">';
										//echo '<script type="text/javascript" src="' . W_JS . 'share.js?10" charset="windows-1251"></script>';
										//echo '<script type="text/javascript">document.write(VK.Share.button(false,{type: "round", text: "Сохранить"}));</script>';
									echo '</div>';
									echo '<div class="service">';
										echo '<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal">Tweet</a>';
									echo '</div>';
									//echo '<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script><a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal">Tweet</a>';
									echo '<div class="service">';
										echo '<iframe src="http://www.facebook.com/plugins/like.php?href=' . trim(W_FULLPATH, '/') . $_SERVER['REQUEST_URI'] . '&layout=button_count&amp;show_faces=false&amp;width=80&amp;action=like&amp;colorscheme=light&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:20px; " allowTransparency="true"></iframe>';
									echo '</div>';
									echo '<div style="clear:both;"></div>';
								echo '</div>';
							//}
							echo '<ul class="bottom_ocenku">';
								if ($arrArticle['essence_type'] != 14){
									echo '<li><strong>Сложность:</strong><div class="slognost">'; echo View_Mark::showMark(1, $arrArticle, 1, 'complexity'); echo '</div></li>';
								}

								echo '
								<li><strong>Качество:</strong><div class="kachestvo">'; echo View_Mark::showMark(1, $arrArticle, 0, 'stars'); echo '</div></li>
							</ul>' .
					  	View_Tags::showTags(split(',', $arrArticle['tags']), $arrArticle['ID_article'], 1, '', W_ABSPATH, ', ', $arrArticle['userDeletedTagsInfo']) . '
						</div>
					</div>
				</div>
			</div>
		</div>';
  }

  /**
   * получаем название и сущность которому принадлежит статья
   */
  public static function getArticleEssence($arrArticle, $onlyNameFlag = false){
  	if (!$onlyNameFlag){
	  	if ($arrArticle['essence_type'] == 11)
	      $return = '<a class="white" href="' . W_ABSPATH . 'articles?idFolder=' . $arrArticle['ID_essence'] . '">' . $arrArticle['folder_name'];
	    elseif ($arrArticle['essence_type'] == 3)
	    	$return = '<a class="white" href="' . W_ABSPATH . 'user/' . $arrArticle['login'] . '/articles/">Дневник ' . $arrArticle['login'];
	    elseif ($arrArticle['essence_type'] == 14)
	    	$return = '<a class="white" href="' . W_ABSPATH . 'developerBlog' . '">Блог разработчиков';
	    $return .= '</a> ';
  	}
  	else {
	  	if ($arrArticle['essence_type'] == 11)
	      $return = $arrArticle['folder_name'];
	    elseif ($arrArticle['essence_type'] == 3)
	    	$return = 'Дневник ' . $arrArticle['login'];
	    elseif ($arrArticle['essence_type'] == 14)
	    	$return = 'Блог разработчиков';
  	}
    return $return;
  }

  /**
   * отображение списка сообществ в упращенном виде
   *
   * @param unknown_type $arrArticle
   */
  public static function displayAllArticleSimple($arrArticle){
  	for ($num = 0; $num <sizeof($arrArticle); $num++){
  		echo '
  		<table id="sidefolderTable"  width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td colspan="2">
					</td>
					<td align="center">
						<span id="rating">Рейтинг</span>
					</td>
					<td align="center">
						<span id="rating">Количесво комментариев</span>
					</td>
				</tr>';
					for ($num=0; $num < sizeof($arrArticle); $num++){
						echo '
						<tr>
							<td class="image">
								<img class="preview" src="' . W_IMAGES . 'icons/playSmallGray.gif' . '"/>
							</td>
							<td class="name">
								<span class="commName"><a href="' . W_ABSPATH . 'article/' . $arrArticle[$num]['ID_article'] . '" class="none"><b>' . $arrArticle[$num]['name'] . '</b></a></span>
							</td>
							<td class="membership">
								<div class="divMembership"><div>
									<span class="membership">'; View_Mark::showStaticMark($arrArticle[$num]['average_mark']); echo '</span><span class="yellowBg">|</span>
								</div></div>
							</td>
							<td class="membership">
								<div class="divMembership"><div>
									<span class="membership">' . $arrArticle[$num]['comment_amount'] . '</span><span class="yellowBg">|</span>
								</div></div>
							</td>
						</tr>
					';
			  	}
				echo '
			</table>';
  	}
  }

  /**
   * функция отображение страницы "Статьи"
   */
  public static function displayArticlesPage($arrArticle, $idFolder = NULL){
		if (sizeof($arrArticle) != 0){
			echo '<div class="info_article">';
				echo '<a name="start"></a>';

				foreach ($arrArticle as $arrArticle) self::displayArticleInColumn($arrArticle);

				echo '<p class="goToTop"><a href="#start" id="showSorting">К началу списка</a></p>';
			echo'</div>';
  	}
  	else
  		self::_showNoContent($idFolder);
  }


  public static function displayArticleInColumn($arrArticle, $fullSizeFlag = false, $folderFlag = false){
		echo '
			<!-- box statua-->
			' . ($fullSizeFlag == false ? '<div class="text_info">' : '<div class="item_text_info">') . '
				<div class="text_info_left">
					<div class="text_info_right">
						<h1 class="crumb ">
							' . ((isset($arrArticle['draft'] ) AND $arrArticle['draft'] == 1) ? '<a href="' . W_ABSPATH . 'draft">Черновик</a>' : '') . '
							' . (!$folderFlag ? self::getArticleEssence($arrArticle) : '') . '
							<a class="last" href="' . W_ABSPATH . 'article/' . $arrArticle['ID_article'] . '">' . $arrArticle['name'] . '</a>
						</h1>
						<div class="top_info_text">
								<ul class="rating">
									<li class="one">' . round($arrArticle['total_mark'], 2) . '</li>
									<li class="second">' . round($arrArticle['average_complexity_mark'], 2) . '</li>
									<li class="coments"><a href="' . W_ABSPATH . 'article/' . $arrArticle['ID_article'] . '#comments">' . $arrArticle['comment_amount'] . '</a></li>
								</ul>
								<div class="right_ifno_text">
									<ul class="info_coments">
										<li class="date">' . Service_Date::getCaseDateForUser($arrArticle['creation']) . '</li>
										<li class="user"><a href="' . W_ABSPATH . 'user/' . $arrArticle['login'] . '/">' . $arrArticle['login'] . '</a></li>
									</ul>' .
									View_Tags::showTagsInList($arrArticle['tags'], 1, 'all_tags') . '
								</div>
							</div>
							<div class="wysiwyg-content">
							' . (($arrArticle['essence_type'] == 14 AND isset($arrArticle['text'])) ? $arrArticle['text'] : $arrArticle['annotation']);
							if (!empty($arrArticle['text']))
								echo '<span class="read"><a href="' . W_ABSPATH . 'article/' . $arrArticle['ID_article'] . '#cut">' . ($arrArticle['cut_text'] ? $arrArticle['cut_text'] : 'Читать далее') . '</a></span>';
						echo '
					</div></div>' . ($fullSizeFlag == false ? '</div>' : '') . '
					' . ($fullSizeFlag == true ? '</div>' : NULL) . '
			</div>';
			echo '<div class="clear"></div>';

  }
  /**
   * вывод формы для сортировки
   */
  public static function displaySortForm($arrSort, $idfolder = NULL){
  	if (isset($arrSort['startDate'])){
  		$arrSort['startDate'] = join('.', array_reverse(split('-', $arrSort['startDate'])));
  		$arrSort['endDate'] = join('.', array_reverse(split('-', $arrSort['endDate'])));

  	}
  	echo '
  	<!--start box top content-->
			<div class="all_article">';
					/*echo '
					<div class="filter">
				  	<form id="smallFilter" method="GET" action="' . W_ABSPATH . 'articles">
							<p><b>Фильтр:</b></p> Создана после <input class="datePicker type="text" name="startDate" id="startDate" value="' . (!empty($arrSort['startDate']) ? $arrSort['startDate'] : '') . '"/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							Ретингом более <input class="datePicker type="text" size="1" ' . ($arrSort['articleFilter'] == 1 ? 'style="margin-right:109px;"' : NULL) . ' id="rating" name="rating" value="' . (!empty($arrSort['rating']) ? $arrSort['rating'] : '') . '"/>
							<input id="filtrSmallBtn" type="image" ' . ($arrSort['articleFilter'] == 1 ? 'style="display:none"' : NULL) . ' name="filterSmall" src="' . W_IMAGES . 'button/btn_filter.gif"/>
							<div id="sort" ' . ($arrSort['articleFilter'] == 0 ? 'style="display:none"' : NULL) . '>
								<div style="margin-left:74px;">
									<p> до <input class="datePicker" type="text" name="endDate" id="endDate" value="' . (!empty($arrSort['startDate']) ? $arrSort['endDate'] : '') . '"/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
									Сложностью менее <input class="datePicker type="text" size="1" id="complexity" name="complexity" value="' . (!empty($arrSort['complexity']) ? $arrSort['complexity'] : '') . '"/></p>
									<p class="duration"><a class="jsHref" onclick="setDay()">День</a>&nbsp;&nbsp;<a class="jsHref" onclick="setWeek()">Неделя</a>&nbsp;&nbsp;<a class="jsHref" onclick="setMonth()">Месяц</a>&nbsp;&nbsp;<a class="jsHref" onclick="setYear()">Год</a></p>
								</div><br/>
								<p>Теги (через запятую) <input class="datePicker type="text" size="80" id="tags" name="tags" value="' . (isset($arrSort['tags']) ? $arrSort['tags'] : '') . '"/></p>';
  							if (!isset($idfolder))
	  							echo '
									<p class="fromFolder">
										<input class="datePickerBox" type="checkbox" id="folder" name="folder"  ' . ($arrSort['likeFolder'] === 1 ? ' checked="checked" disabled="disabled" ' : ($arrSort['folder'] === 1  ? ' checked="checked"' : NULL)) . '> Из разделов
									 	<input type="checkbox" id="likeFolder" onClick="' . ($arrSort['likeFolder'] == 1 ? 'folderSelectOff();' : 'folderSelect();') . '" name="likeFolder"  ' . ($arrSort['likeFolder'] == 1  ? 'checked="checked"' : NULL) . '> Из любимых разделов
									 </p><br/>';
								echo '
					  		<p>
									<b>Сортировка:</b>&nbsp;&nbsp;&nbsp;&nbsp;
							  		Поле
							  		<select id="sort" name="sort">
							  			<option value="1" ' . ($arrSort['sort'] == 1 ? 'selected="selected"' : NULL) . '>Дата</option>
							  			<option value="2" ' . ($arrSort['sort'] == 2 ? 'selected="selected"' : NULL) . '>Рейтинг</option>
							  			<option value="3" ' . ($arrSort['sort'] == 3 ? 'selected="selected"' : NULL) . '>Сложность</option>
							  			<option value="4" ' . ($arrSort['sort'] == 4 ? 'selected="selected"' : NULL) . '>Количесво комментариев</option>
							  			<option value="5" ' . ($arrSort['sort'] == 5 ? 'selected="selected"' : NULL) . '>Количество просмотров</option>
							  			<option value="6" ' . ($arrSort['sort'] == 6 ? 'selected="selected"' : NULL) . '>Количество посетителей</option>
							  		</select>
							  		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						  	Направление:&nbsp;&nbsp;&nbsp;
						  		<input type="radio" name="direction" value="1" ' . ($arrSort['direction'] != 2 ? 'checked' : NULL) . '> прямое&nbsp;&nbsp;&nbsp;&nbsp;
						  		<input type="radio" name="direction" value="2" ' . ($arrSort['direction'] == 2 ? 'checked' : NULL) . '> обратное</p>
								<p><input id="tagsBtn" type="image" name="filterBig" src="' . W_IMAGES . 'button/btn_filter.gif"/></p><br />
								' . (isset($idfolder) ? '<input type="hidden" name="idFolder" value="' . $idfolder . '"/>' : NULL) . '
							</div>
					  </form>
					</div>
				<div>';
					if ($arrSort['articleShow'] == 1)
						echo 'Показывать: <strong><a id="showSort" href="' . W_ABSPATH . 'articles?articleShow=0' . (isset($idfolder) ? '&idFolder=' . $idfolder : NULL) . '">все</a></strong>';
					elseif ($arrSort['articleShow'] == 0)
						echo 'Показывать: <strong><a id="showSort" href="' . W_ABSPATH . 'articles?articleShow=1' . (isset($idfolder) ? '&idFolder=' . $idfolder : NULL) . '">C не отрицательным рейтингом</a></strong>';
					echo '
					<a id="showSorting" onClick="' . ($arrSort['articleFilter'] == 0 ? 'showSorting(' . $idfolder . ');' : 'closeSorting(' . $idfolder . ');') . ' return false;" href="">' . ($arrSort['articleFilter'] ? 'Простой фильтр' : 'Расширенная фильтрация и сортировка') .'</a>
				</div>';*/
		$html = '
          <div class="filter-simple list_qwestion" style="display: ' . (!$arrSort['articleFilter'] ? 'block' : 'none') . ';">
   				  <form action="' . W_ABSPATH . 'articles" method="GET" id="smallFilter">
   				    <table class="filterTable" border="0" cellspacing="0" cellpadding="0">
   				      <!--<tr>
   				        <th colspan="4">Фильтр</th>
   				      </tr>-->
   				     <tr>
   				       <td class="col_1" style="width: 89px;">Создано после</td>
   				       <td class="col_2"><input class="datePicker" type="text" name="startDate" id="pickDate" value="' . (!empty($arrSort['startDate']) ? $arrSort['startDate'] : '') . '" /></td>
   				       <td class="col_3">Рейтингом более</td>
   				       <td class="col_4"><input class="datePicker" type="text" size="1" id="rating" name="rating" value="' . (!empty($arrSort['rating']) ? $arrSort['rating'] : '') . '" /></td>
   				     </tr>
   				     <tr>
   				       <td class="sbmt_left" colspan="4">
   				          <input id="tagsBtn" type="image" style="margin-top:2px;" name="sbmtShortFilter" src="' . W_IMAGES . 'button/btn_filter.gif" style="margin:0" />
   				          <input type="hidden" name="fullFilter" />
   				         <a id="showSorting" onClick="showSorting();return false;" href="#" style="margin-left:65px">Расширенная фильтрация и сортировка</a>
   				       </td>
   				     </tr>
   				    </table>
   				  </form>
    		  </div>
  		  ';
  $html .= '  <div class="filter list_qwestion" style="display: ' . ($arrSort['articleFilter'] ? 'block' : 'none') . ';">
   				  <form action="' . W_ABSPATH . 'articles" method="GET" id="fullFilter">
   				    <table class="filterTable" border="0" cellspacing="0" cellpadding="0">
   				     <tr>
   				       <th colspan="4">Фильтр</th>
   				     </tr>
   				     <tr>
   				       <td class="col_1">Создано после</td>
   				       <td class="col_2"><input class="datePicker" type="text" name="startDate" id="startDate" value="' . (!empty($arrSort['startDate']) ? $arrSort['startDate'] : '') . '" /></td>
   				       <td class="col_3">Рейтингом более</td>
   				       <td class="col_4"><input class="datePicker" type="text" size="1" id="rating" name="rating" value="' . (!empty($arrSort['rating']) ? $arrSort['rating'] : '') . '" /></td>
   				     </tr>
   				     <tr>
   				       <td class="col_1">до</td>
   				       <td class="col_2">
   				         <input class="datePicker" type="text" name="endDate" id="endDate" value="' . (!empty($arrSort['startDate']) ? $arrSort['endDate'] : NULL) . '"/>
   				         <p class="duration" style="display: block;"><a class="jsHref" onclick="setDay();">День</a>&nbsp;&nbsp;<a class="jsHref" onclick="setWeek();">Неделя</a>&nbsp;&nbsp;<a class="jsHref" onclick="setMonth();">Месяц</a>&nbsp;&nbsp;<a class="jsHref" onclick="setYear();">Год</a></p>
   				       </td>
   				       <td class="col_3">Сложностью менее</td>
   				       <td class="col_4"><input class="datePicker type="text" size="1" id="complexity" name="complexity" value="' . (!empty($arrSort['complexity']) ? $arrSort['complexity'] : '') . '"/></td>
   				     </tr>
   				     <tr>
   				       <td class="col_1" style="padding-top: 7px;">Укажите теги</td>
   				       <td class="col_2" colspan="3"><input class="stFilterInput" type="text" id="tags" name="tags" value="' . (isset($arrSort['tags']) ? $arrSort['tags'] : '') . '" /></td>
   				     </tr>';
							 if (!isset($idfolder))
	   				     $html .= '<tr>
	   				       <td class="col_1"><p style="display: inline; position: relative; bottom: 2px;">Из разделов</p></td>
	   				       <td class="col_2" colspan="3">
	   				       	<input class="datePickerBox" type="checkbox" id="folder" name="folder"  ' . ($arrSort['likeFolder'] === 1 ? ' checked="checked" disabled="disabled" ' : ($arrSort['folder'] === 1  ? ' checked="checked"' : NULL)) . '>
	   				       	<p style="display: inline; position: relative; top: 1px; padding-left: 12px;">Из любимых разделов</p>  <input type="checkbox" id="likeFolder" onClick="' . ($arrSort['likeFolder'] == 1 ? 'folderSelectOff();' : 'folderSelect();') . '" name="likeFolder"  ' . ($arrSort['likeFolder'] == 1  ? 'checked="checked"' : NULL) . '>
	 				       	</td>
	   				     </tr>';
   				     $html .= '
   				     <tr>
   				       <th colspan="4" style="padding-top: 15px;">Сортировка</th>
   				     </tr>
   				     <tr>
   				       <td class="col_1" style="padding-top: 7px;">Выберите поле</th>
   				       <td class="col_2">
                   <select id="sort" name="sort" style="width: 172px;">
						  		 	 <option value="1" ' . ($arrSort['sort'] == 1 ? 'selected="selected"' : NULL) . '>Дата</option>
						  		 	 <option value="2" ' . ($arrSort['sort'] == 2 ? 'selected="selected"' : NULL) . '>Рейтинг</option>
						  		 	 <option value="3" ' . ($arrSort['sort'] == 3 ? 'selected="selected"' : NULL) . '>Сложность</option>
						  			 <option value="4" ' . ($arrSort['sort'] == 4 ? 'selected="selected"' : NULL) . '>Количесво комментариев</option>
						  			 <option value="5" ' . ($arrSort['sort'] == 5 ? 'selected="selected"' : NULL) . '>Количество просмотров</option>
						  			 <option value="6" ' . ($arrSort['sort'] == 6 ? 'selected="selected"' : NULL) . '>Количество посетителей</option>
						  		 </select>
   				       </td>
     				     <td class="col_3" colspan="2" style="padding-right:7px;padding-left:10px;">
       				     <label for="direction_1" style="padding-top:0px; padding-right:0px;">&nbsp;прямой порядок</label>
       				     <input type="radio" name="direction" id="direction_1" value="1" style="position:relative;left:1px"  ' . ($arrSort['direction'] != 2 ? 'checked' : NULL) . '><br />
       				     <label for="direction_2" style="padding-top:0px; padding-right:0px;">&nbsp;обратный порядок</label>
  						  	<input type="radio" name="direction" id="direction_2" value="2" ' . ($arrSort['direction'] == 2 ? 'checked' : NULL) . '>
     				     </td>
   				     </tr>
   				     <tr>
   				       <td colspan="4" style="font-size:1px;height:5px;"></th>
   				     </tr>
   				     <tr>
   				       <td class="sbmt_left" colspan="2">
   				         <input id="tagsBtn" type="image" name="sbmtBigFilter" src="' . W_IMAGES . 'button/btn_filter.gif" style="margin:0" />
   				         <input type="hidden" name="fullFilter" />
   				       </td>
   				       <td class="sbmt_right" colspan="2">
   				         <a id="showSorting" onClick="closeSorting();return false;" href="#">Обычный фильтр</a>
   				       </td>
   				     </tr>
   				    </table>
   				  </form>
    			</div>
			</div>';
  	View_Common::showRoundedBox($html, 'width: 460px;margin-top:12px;height:auto;');
  }


  /**
   * выводит Статью в форме для редактирования
   *
   * @param int $idArticle
   * @param array $arrArticle
   */
  public static function displayArticleForEdit($arrArticlePost, $arrArticle, $idFolder = NULL, $title){

  if (isset($arrArticlePost['draft']) AND $arrArticlePost['draft'] == 1)
  	$draft = true;
  elseif (isset($arrArticle['draft']) AND $arrArticle['draft'] == 1)
  	$draft = true;

  echo '
<div id="main_forms">';
	  echo '
		<form id="niceCommonForm" method="post" onsubmit="$(\'#ID_folder\').val(treeStructure.getIdFolderFromEditTree(\'article_edit\'));" action="' . W_ABSPATH . (isset($arrArticle) ? 'editArticle/' . $arrArticle['ID_article'] : 'newArticle/' . ((int)$idFolder ? $idFolder . '/' : NULL)) . '">';
	  	echo '<br />
			<div class="box_trext_form">
				<div class="info_label isolated" style="width:500px">';
	  	$isToPersonalBlog = ((isset($arrArticle['essence']) AND $arrArticle['essence'] == 3) OR $arrArticlePost == true);

	  	View_TreeStructure::viewFolderSelectLinks($idFolder, TreeStructure::getFolderName($idFolder), 'article', NULL, '', false, true, true, $isToPersonalBlog);

	  	echo '<input type="checkbox" id="blog" name="blog" ' . ($isToPersonalBlog ? 'onClick="unselectPersonalBlog();" checked="checked"' : 'onClick="selectPersonalBlog(\'article\');"') . '>&nbsp;Личный блог
					<p class="notice" style="padding-top:5px;">Укажите раздел для добавления статьи либо укажите, что статья добавляется в личный блог.</p>
				</div>
			</div>';

	  	echo '
	  	<div class="box_trext_form">
					<label>Заголовок</label>
					<div class="info_label">
						<input type="text" name="articleTitle" id="articleTitle" class="tx" value="';
			  		if (isset($arrArticlePost['articleTitle']))
			  			echo  $arrArticlePost['articleTitle'];
						elseif (isset($arrArticle['name']))
							echo 	$arrArticle['name'];
						echo
					'"/>
					</div>
				</div>';

			echo '
			<div class="box_trext_form">
				<label>Краткая аннотация (текст до ката)</label>
				<div class="info_label" id="wAnnotationBeforeCutDiv" >
				<textarea class="tx_big wysiwygAdmin" type="text" name="annotation" id="wAnnotationBeforeCut"> ';
		  		if (isset($arrArticlePost['annotation']))
		  			echo  $arrArticlePost['annotation'];
					elseif (isset($arrArticle['annotation']))
						echo 	$arrArticle['annotation'];
					echo
				'</textarea>
				 <div class="wysiwyg2" id="wAnnotationBeforeCut_w2" style="display:none">';
		  		if (isset($arrArticlePost['annotation']))
		  			echo  $arrArticlePost['annotation'];
					elseif (isset($arrArticle['annotation']))
						echo 	$arrArticle['annotation'];
					echo
				'</div>
				</div>
			</div>';

			echo '
			<div class="box_trext_form">
				<label>Кат</label>
				<div class="info_label">
			<input class="tx with-notice" type="text" name="cut_text" id="wcut_text" value="';
	  		if (isset($arrArticlePost['cut_text']))
	  			echo  $arrArticlePost['cut_text'];
				elseif (isset($arrArticle['cut_text']))
					echo 	$arrArticle['cut_text'];
				else echo 'Читать далее';
			 echo '"/>
				<p class="notice">При выводе в виде списка текст после аннотации (из поля Текст) будет заменён ссылкой на полную версию</p>
				</div>
			</div>';

		 	echo '
			<div class="box_trext_form">
				<label>Текст (текст после ката)</label>
				<div class="info_label">
					<textarea style="height: 600px;" class="tx_big wysiwygAdmin" id="wysiwygAdmin_1" type="text" name="articleText">';
			  		if (isset($arrArticlePost['articleText']))
			  			echo  $arrArticlePost['articleText'];
						elseif (isset($arrArticle['text']))
							echo 	$arrArticle['text'];
						echo
					'</textarea>
					 <div class="wysiwyg2" id="wysiwygAdmin_1_w2" style="display:none">';
		  		if (isset($arrArticlePost['articleText']))
		  			echo  $arrArticlePost['articleText'];
					elseif (isset($arrArticle['text']))
						echo 	$arrArticle['text'];
					echo
				'</div>
					</div>
				</div>';
//			if (!empty($arrArticle)) { //Если это режим редактирования
//  			//Обработка тегов до вывода
//        $arrFoldersIDs = TreeStructure::getRootFolders($idFolder, true);
//        if (!empty($arrFoldersIDs)) $arrFoldersIDs[] = $idFolder;
//          else $arrFoldersIDs = array($idFolder);
//        $arrParentFoldersNames = TreeStructure::getFoldersNamesByIDs($arrFoldersIDs); //получаем имена родительских разделов
//        $arrTagsToShow = Tags::removeTagsFromArray($arrParentFoldersNames, explode(', ', $arrArticle['tags']));
//        $arrArticle['tags'] = join(', ', $arrTagsToShow);
//			}
			echo '
			<div class="box_trext_form">
				<label>Теги</label>
				<div class="info_label">
					<input class="tx with-notice" type="text" id="tags-list" name="tags" value="' . (isset($arrArticlePost['tags']) ? $arrArticlePost['tags'] : (isset($arrArticle['tags']) ? $arrArticle['tags'] : NULL)) . '"/><br />
					<p class="notice">Укажите теги через запятую (минимум <em>два тега</em>). Теги, совпадающие с названиями родительских разделов, включаются в список автоматически.</p>
				</div>
			</div>';
			if (empty($arrArticle)) { //Если это режим создания
      	echo '<div id="userContentRequest" style="display:none;">';
        	$arrCRList4User = ContentRequest::getListForUser(1);
        	View_ContentRequest::showListForUser($arrCRList4User, 1);
      	echo '</div>';
        View_ContentRequest::showLinkUI2Form($arrArticlePost, 1);
			}
			echo '<p><input type="checkbox" id="draft" name="draft" ' . (isset($draft) ? 'checked="checked"' : '') . '/> Сохранить в черновики</p>
					  <input class="main_btn" name="editArticle" type="image" src="' . W_IMAGES . 'button/btn_main_otpravit.gif" />';
			echo '<input type="hidden" id="ID_folder" name="idFolder" value="' . (isset($idfolder) ? $idfolder : "") . '" />';
			echo '<input type="hidden" id="idArticle" name="idArticle" value="' . (isset($arrArticle['ID_article']) ? $arrArticle['ID_article'] : "") . '" />';
			echo '
		</form>
</div>';

	/*echo '<a class="" id="openCodeGenerator">Добавить подсветку кода</a>';
	echo '<a class="" id="closeCodeGenerator">Закрыть</a>';
	if (!isset($idGeneratorOfCodeHighlight))
		$idGeneratorOfCodeHighlight = NULL;
	if (!isset($arrGeneratorOfCodeHighlight))
		$arrGeneratorOfCodeHighlight = array();

	View_Tutorial::viewGeneratorOfCodeHighlight(Code::getAllLanguageFolder(), $idGeneratorOfCodeHighlight, $arrGeneratorOfCodeHighlight);*/
  }

  /**
   * оределяем сортировку статей при выводе
   *
   * @param unknown_type $order
   * @param unknown_type $direction
   */
  public static function getSorting($order, $direction){
  	switch ($order){//Определяем поле сортировки
			case 1:
				$sorting['orderField'] = 'creation'; break;
			case 2:
				$sorting['orderField'] = 'average_mark'; break;
			case 3:
				$sorting['orderField'] = 'name'; break;
		}

		if ($order != 3){
			switch ($direction){//Определяем направление сортировки
				case 1:
					$sorting['directionDb'] = 'DESC'; break;
				case 2:
					$sorting['directionDb'] = 'ASC'; break;
			}
		}
		else {
			switch ($direction){//Определяем направление сортировки
				case 1:
					$sorting['directionDb'] = 'ASC'; break;
				case 2:
					$sorting['directionDb'] = 'DESC'; break;
			}
		}
		return $sorting;
  }

  /**
   * получаем ссылки для сортировки статей
   *
   * @param unknown_type $order
   * @param unknown_type $direction
   */
  public static function displayOrderReferences($order, $direction){
  	echo '<a class="none" href = ' . W_ABSPATH . 'article/articles/1/1/1/>';
				if ($order == 1 AND $direction == 1)
					echo '
					<img src="' . W_IMAGES . 'icons/downSelect.gif" alt="">';
				else
					echo '
					<img src="' . W_IMAGES . 'icons/down.gif" alt="">';
				echo '
			</a>
				<span>По дате</span>
			<a class="none" href = ' . W_ABSPATH . 'article/articles/1/2/1/>';
				if ($order == 1 AND $direction == 2)
					echo '
				<img src="' . W_IMAGES . 'icons/upSelect.gif" alt="">';
				else
					echo '
					<img src="' . W_IMAGES . 'icons/up.gif" alt="">';
				echo '
			</a>';

		echo '<a class="none" href = ' . W_ABSPATH . 'article/articles/2/1/1/>';
						if ($order == 2 AND $direction == 1)
							echo '
							<img src="' . W_IMAGES . 'icons/downSelect.gif" alt="">';
						else
							echo '
							<img src="' . W_IMAGES . 'icons/down.gif" alt="">';
						echo '
					</a>
						<span>По рейтингу</span>
					<a class="none" href = ' . W_ABSPATH . 'article/articles/2/2/1/>';
						if ($order == 2 AND $direction == 2)
							echo '
						<img src="' . W_IMAGES . 'icons/upSelect.gif" alt="">';
						else
							echo '
							<img src="' . W_IMAGES . 'icons/up.gif" alt="">';
						echo '
					</a>';

		echo '<a class="none" href = ' . W_ABSPATH . 'article/articles/3/1/1/>';
						if ($order == 3 AND $direction == 1)
							echo '
							<img src="' . W_IMAGES . 'icons/downSelect.gif" alt="">';
						else
							echo '
							<img src="' . W_IMAGES . 'icons/down.gif" alt="">';
						echo '
					</a>
						<span>По названию</span>
					<a class="none" href = ' . W_ABSPATH . 'article/articles/3/2/1/>';
						if ($order == 3 AND $direction == 2)
							echo '
						<img src="' . W_IMAGES . 'icons/upSelect.gif" alt="">';
						else
							echo '
							<img src="' . W_IMAGES . 'icons/up.gif" alt="">';
						echo '
					</a>';
  }

  private static function _showNoContent($idFolder = NULL) {
    if (is_null($idFolder)) $idFolder = 0;
    echo '<div class="no_essences_notice">
					  <p>Статей по данному запросу не найдено.</p>
  	        <p>Вы можете <a href="' . W_ABSPATH . 'newArticle/' . ($idFolder ? $idFolder : '') . '">добавить статью</a><a href="' . W_ABSPATH . 'newArticle/' . ($idFolder ? $idFolder : '') . '"><img class="arrowRight" src="' . W_IMAGES . 'arrowRight.gif" alt="" /></a></p>
  	      </div>';
  }
}
?>
